package com.ds.lens.flink.monitor.monitorjob.function;

import com.ds.lens.data.common.constant.DetectionTypeEnum;
import com.ds.lens.data.common.document.dto.MonitorEvent;
import com.ds.lens.flink.monitor.common.MonitorDefinitionFactory;
import com.ds.lens.flink.monitor.common.bo.MetricBundle;
import com.ds.lens.flink.monitor.common.bo.MonitorDefinition;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.java.tuple.Tuple2;

import java.util.Map;

/**
 * Description:
 *
 * @author WeiShaoying
 * @date 2020-05-11
 */
public class DynamicDetectionFilter implements FilterFunction<Tuple2<MetricBundle, Map<String, MonitorEvent>>> {
    private static final long serialVersionUID = -3327895839318113992L;

    @Override
    public boolean filter(Tuple2<MetricBundle, Map<String, MonitorEvent>> tuple2) throws Exception {
        MonitorDefinition definition = MonitorDefinitionFactory.get().getMonitorDefinitionByState(tuple2.f0.getState());
        return definition.getDetectionMethod() == DetectionTypeEnum.DYNAMIC_STATE.getCode();
    }
}
